<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>isCached()</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="Smarty 3 Manual">
<link rel="up" href="api.functions.html" title="Chapter 14. Smarty Class Methods">
<link rel="prev" href="api.get.template.vars.html" title="getTemplateVars()">
<link rel="next" href="api.load.filter.html" title="loadFilter()">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">isCached()</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="api.get.template.vars.html">Prev</a> </td>
<th width="60%" align="center">Chapter 14. Smarty Class Methods</th>
<td width="20%" align="right"> <a accesskey="n" href="api.load.filter.html">Next</a>
</td>
</tr>
</table>
<hr>
</div>
<div class="refentry" title="isCached()">
<a name="api.is.cached"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>Name</h2>
<p>isCached() — returns true if there is a valid cache for this template</p>
</div>
<div class="refsect1" title="Description">
<a name="id435350"></a><h2>Description</h2>
<code class="methodsynopsis"><span class="type">bool </span><span class="methodname">isCached</span>(<span class="methodparam"><span class="type">string </span><span class="parameter">template</span></span>,<br>              <span class="methodparam"><span class="type">string </span><span class="parameter">cache_id</span></span>,<br>              <span class="methodparam"><span class="type">string </span><span class="parameter">compile_id</span></span>);</code><div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem"><p>
   This only works if <a class="link" href="variable.caching.html" title="$caching">
    <em class="parameter"><code>$caching</code></em></a> is set to one of <code class="literal">Smarty::CACHING_LIFETIME_CURRENT</code> or <code class="literal">Smarty::CACHING_LIFETIME_SAVED</code> to enable caching. See the
   <a class="link" href="caching.html" title="Chapter 15. Caching">caching section</a> for more info.
  </p></li>
<li class="listitem"><p>
   You can also pass a <em class="parameter"><code>$cache_id</code></em> as an optional second
   parameter in case you want
   <a class="link" href="caching.multiple.caches.html" title="Multiple Caches Per Page">multiple caches</a>
   for the given template.
  </p></li>
<li class="listitem"><p>
   You can supply a
   <a class="link" href="variable.compile.id.html" title="$compile_id"><em class="parameter"><code>$compile id</code></em></a>
   as an optional third parameter. If you omit that parameter the persistent
   <a class="link" href="variable.compile.id.html" title="$compile_id">
   <em class="parameter"><code>$compile_id</code></em></a> is used if its set.
  </p></li>
<li class="listitem"><p>
   If you do not want to pass a <em class="parameter"><code>$cache_id</code></em> but want to
   pass a <a class="link" href="variable.compile.id.html" title="$compile_id">
   <em class="parameter"><code>$compile_id</code></em></a> you have to pass
   <code class="constant">NULL</code> as a <em class="parameter"><code>$cache_id</code></em>.
  </p></li>
</ul></div>
<div class="note" title="Technical Note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Technical Note</h3>
<p>
   If <code class="varname">isCached()</code> returns <code class="constant">TRUE</code> it actually loads the
   cached output and stores it internally. Any subsequent call to
   <a class="link" href="api.display.html" title="display()"><code class="varname">display()</code></a> or
   <a class="link" href="api.fetch.html" title="fetch()"><code class="varname">fetch()</code></a>
   will return this internally stored output and does not try to reload
   the cache file. This prevents a race condition that may occur when a
   second process clears the cache between the calls to
   <code class="varname">isCached()</code> and to
   <a class="link" href="api.display.html" title="display()"><code class="varname">display()</code></a>
   in the example above. This also means calls to
   <a class="link" href="api.clear.cache.html" title="clearCache()"><code class="varname">clearCache()</code></a>
   and other changes of the cache-settings may have no effect after
   <code class="varname">isCached()</code> returned <code class="constant">TRUE</code>.
  </p>
</div>
<div class="example">
<a name="id435849"></a><p class="title"><b>Example 14.32. isCached()</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
$smarty-&gt;setCaching(Smarty::CACHING_LIFETIME_CURRENT);

if(!$smarty-&gt;isCached('index.tpl')) {
// do database calls, assign vars here
}

$smarty-&gt;display('index.tpl');
?&gt;

   </pre></div>
</div>
<br class="example-break"><div class="example">
<a name="id435867"></a><p class="title"><b>Example 14.33. isCached() with multiple-cache template</b></p>
<div class="example-contents"><pre class="programlisting">

&lt;?php
$smarty-&gt;setCaching(Smarty::CACHING_LIFETIME_CURRENT);

if(!$smarty-&gt;isCached('index.tpl', 'FrontPage')) {
  // do database calls, assign vars here
}

$smarty-&gt;display('index.tpl', 'FrontPage');
?&gt;

   </pre></div>
</div>
<br class="example-break"><p>
    See also
    <a class="link" href="api.clear.cache.html" title="clearCache()"><code class="varname">clearCache()</code></a>,
    <a class="link" href="api.clear.all.cache.html" title="clearAllCache()"><code class="varname">clearAllCache()</code></a>,
    and
    <a class="link" href="caching.html" title="Chapter 15. Caching">caching section</a>.
  </p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="api.get.template.vars.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="api.functions.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="api.load.filter.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">getTemplateVars() </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> loadFilter()</td>
</tr>
</table>
</div>
</body>
</html>
